module Magic 
  class Singleton

    def self.singleton_instance= instance
      self.send(:class_variable_set, '@@instance', instance)
      (instance.public_methods.sort - Object.public_methods).each do |method|
        #puts "making shortcut for #{method}"
        class_eval "def self.#{method}(*args); @@instance.send(:#{method}, *args); end"
      end
      true
    end
    
    def self.singleton_instance
      self.send(:class_variable_get, '@@instance')
    end

    def initialize
      raise 'Singletons cannot be initialized.'
    end
  end

end